/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = __jboss_get_map_bytes.c                          */
/*  NOTE      =                                                    */
/*  DATE      = 2015/11/19 by geyh                                 */
/*******************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <CUnit/Basic.h>
#include <CUnit/CUnit.h>

#include <jbossmq/jbossmq_comm.h>
#include <jbossmq/jbossmq_core.h>
#include "frcomm.h"
#include "frmem.h"
#include "conntrack.h"
#include "frct_comm.h"
#include "frbyte_buffer.h"
#include "frlist.h"
#include "frreport_comm.h"
#include "apmtest_cunit.h"
#include "apmtest_comm.h"

#include "../../../src/module/jbossmq/config.h"


static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}

int __jboss_get_map_bytes(char **pp_data, int *p_i_data_len, char *p_key, Frreport_body_data *p_st_body_data);

static void __case1(void)
{
    int i_ret = 0, i_data_len = 0;
    char *p_data = NULL, *p_data_tmp = NULL;
    Frreport_body_data *p_st_body_data = NULL;
    Conntrack *p_st_conn = NULL;

    i_ret = apmtest_create_ct(&p_st_conn, jboss_session_destroy, (char *)"192.168.0.1", (char *)"192.168.0.35", 5460, 5672);
    p_st_body_data = frreport_body_new_l7 (p_st_conn);

    p_data = (char *)frmemdup((char *)"\x00\x00\x00\x04\x65\x00\x65\x00\x03", 9);
    i_data_len = 9;

    p_data_tmp = p_data;

    i_ret = __jboss_get_map_bytes(&p_data_tmp, &i_data_len, (char *)"value", p_st_body_data);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT(memcmp(p_data_tmp,(char *)"\x03", 1) == 0);
    CU_ASSERT_EQUAL(i_data_len, 1);

    frreport_body_free(&p_st_body_data);
    apmtest_destroy_ct(&p_st_conn);
    frfree(p_data);

    return;
}

static void __case2(void)
{
    int i_ret = 0, i_data_len = 0;
    char *p_data = NULL, *p_data_tmp = NULL;
    Frreport_body_data *p_st_body_data = NULL;
    Conntrack *p_st_conn = NULL;

    i_ret = apmtest_create_ct(&p_st_conn, jboss_session_destroy, (char *)"192.168.0.1", (char *)"192.168.0.35", 5460, 5672);
    p_st_body_data = frreport_body_new_l7 (p_st_conn);

    p_data = (char *)frmemdup((char *)"\x00\x00\x00\x04\x65\x00\x65", 7);
    i_data_len = 7;

    p_data_tmp = p_data;

    i_ret = __jboss_get_map_bytes(&p_data_tmp, &i_data_len, (char *)"value", p_st_body_data);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(i_data_len, 0);

    frreport_body_free(&p_st_body_data);
    apmtest_destroy_ct(&p_st_conn);
    frfree(p_data);

    return;
}


int add_suite___jboss_get_map_bytes(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" __jboss_get_map_bytes()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    CU_add_test(pSuite, "case1", __case1);
    CU_add_test(pSuite, "case2", __case2);


    return FR_SUCC;

}
